home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / cgazv4n3.zip / PSP.C < prev    next >
C/C++ Source or Header  |  1990-02-01  |  6KB  |  163 lines

  1. /******************************  PSP.C  *****************************
  2. *  DESC:       Program to print text files on PostScript printers.  *
  3. *  AUTHOR:     Marv Luse, Ithaca Street Software, Inc.              *
  4. *  DATE:       December, 1989                                       *
  5. *  COPYRIGHT:  Use freely as long as authorship is acknowledged.    *
  6. ********************************************************************/
  7.  
  8. #include "stdlib.h"
  9. #include "stdio.h"
  10. #include "string.h"
  11. #include "time.h"
  12.  
  13. /*
  14.  *   Notes:  (1) Program creates an 8-1/2" x 11" page with 3/4"
  15.  *               margins all around.  Top 1/4" and bottom 1/4"
  16.  *               of active page area used for header and footer.
  17.  *
  18.  *           (2) All page coords are in points (72 points = 1 inch)
  19.  *
  20.  *           (3) Page origin (0,0) located at bottom left, yielding:
  21.  *
  22.  *               ┌──────────────────────────────────────┐
  23.  *               │                                      │
  24.  *               │    + (54,738)         (558,738) +    │
  25.  *               │                                      │
  26.  *               │                                      │
  27.  *               /                                      /
  28.  *               .         Page Coordinate Space        .
  29.  *               .              in Points               .
  30.  *               /                                      /
  31.  *               │                                      │
  32.  *               │                                      │
  33.  *               │    + (54,54)           (558,54) +    │
  34.  *               │                                      │
  35.  *               └──────────────────────────────────────┘
  36.  *
  37.  *           (4) Control char handling:
  38.  *
  39.  *               Carriage Return (0Dh) causes end-of-line
  40.  *               Line Feed (0Ah) ignored
  41.  *               Form Feed (0Ch) causes end-of-line and end-of-page
  42.  *               Tab Char (09h) expands to TAB_SIZE blanks
  43.  *               All other codes treated as text.
  44.  *
  45.  *           (5) To handle files with ASCII values above 127
  46.  *               the program should be compiled with default
  47.  *               char type of unsigned (/J on MSC, -K on TurboC).
  48.  */
  49.  
  50. #define MAX_LEN     80     /* File Names Buffer Length */
  51. #define HDR_HGT     18     /* Page header space in points */
  52. #define FTR_HGT     18     /* Page footer space in points */
  53. #define LINE_SIZE  132     /* I/O buffer length */
  54. #define TAB_SIZE     5     /* number of blanks per tab */
  55.  
  56. /* special characters */
  57. #define TAB_CH       9
  58. #define FF_CH       12
  59. #define CR_CH       13
  60. #define LF_CH       10
  61.  
  62. /* macro to test for end-of-line */
  63. #define eoln( c )  ( ((c==CR_CH) || (c==FF_CH) || (c==0) ) ? 1 : 0 )
  64.  
  65. /* macro to test for end-of-page */
  66. #define eopg( c, n )  ( ((c==FF_CH) || (n>=LnPerPg)) ? 1 : 0 )
  67.  
  68. /* if not using RIPS Image 4000, undefine RIPS */
  69. #define RIPS 1
  70.  
  71. char FileToPrint[MAX_LEN+1] = "",            /* file to be printed */
  72.      PrintDevice[MAX_LEN+1] = "LPT2",              /* printer port */
  73.      DateAndTime[28],                             /* time and date */
  74.      FontName[MAX_LEN+1]    = "Courier";            /* font to use */
  75.  
  76. int  PtSize  = 11,                           /* text hgt in points */
  77.      LnSize  = 12,                           /* line hgt in points */
  78.      LnPerPg = 0,                                /* lines per page */
  79.      LineNo  = 0,                           /* current line number */
  80.      PageNo  = 0;                           /* current page number */
  81.  
  82. int  XLft, XRgt, XCur,                /* page coordinate variables */
  83.      YTop, YBot, YCur;
  84.  
  85. time_t currentT;                                   /* current time */
  86.  
  87. FILE   *fTxt,                                      /* text file in */
  88.        *fPrt;                                       /* printer out */
  89.  
  90. /*-----------------------------------------------------------------*/
  91.  
  92. /* display a message and exit */
  93.  
  94. void exit_pgm( char *msg, int retv )
  95. {
  96.     printf( "\n%s", msg );
  97.     exit( retv );
  98. }
  99.  
  100. /*-----------------------------------------------------------------*/
  101.  
  102. /* explain program usage */
  103.  
  104. void explain_pgm( void )
  105. {
  106.     printf( "\n" );
  107.     printf( "\nPSP - Program to print text files on PostScript printers" );
  108.     printf( "\n" );
  109.     printf( "\nusage:  PSP  file_to_print  [printer_port]" );
  110.     printf( "\n             file_to_print : path to an ASCII text file" );
  111.     printf( "\n             printer_port  : path to printer [def=LPT2]" );
  112.     printf( "\n" );
  113. }
  114.  
  115. /*-----------------------------------------------------------------*/
  116.  
  117. /* initialize for processing */
  118.  
  119. void start_up( char *f_in, char *f_out )
  120. {
  121.     int i;
  122.  
  123.     fTxt = fopen( f_in, "rt" );
  124.     if( fTxt == NULL )  exit_pgm( "Could not locate input file", 8);
  125.  
  126.     fPrt = fopen( f_out, "wt" );
  127.     if( fPrt == NULL )  exit_pgm( "Error opening printer", 8);
  128.  
  129.     time( ¤tT );
  130.     strcpy( DateAndTime, ctime( ¤tT ) );
  131.     /* get rid of trailing newline character copied from ctime */
  132.     i = 0;
  133.     while( DateAndTime[i] >= ' ' ) i++;
  134.     DateAndTime[i] = 0;
  135. }
  136.  
  137. /*-----------------------------------------------------------------*/
  138.  
  139. /* clean up before returning to DOS */
  140.  
  141. void shut_dn( void )
  142. {
  143.     fclose( fTxt );
  144.     fclose( fPrt );
  145.     printf( "\nTotal page(s) printed = %d", PageNo );
  146. }
  147.  
  148. /*-----------------------------------------------------------------*/
  149.  
  150. /* function to write font-select code */
  151.  
  152. void set_font( void )
  153. {
  154.     fprintf( fPrt, "\n/%s findfont", FontName );
  155.     fprintf( fPrt, "\n%d scalefont", PtSize );
  156.     fprintf( fPrt, "\nsetfont" );
  157. }
  158.  
  159. /*-----------------------------------------------------------------*/
  160.  
  161. /* function to draw a line between passed endpoints */
  162.  
  163. void draw_